﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data.SqlClient;

namespace sdamarketing
{
    public class Zainteresiranost
    {
        public static void AddInteresi(int idOblastInteres,int koeficient,int idUser)
        {
            SqlConnection connection = ConnectionMenager.GetConnection();

            SqlParameter idOblastInteresParam = new SqlParameter("@idOblastInteresParam", idOblastInteres);
            SqlParameter koeficientParam = new SqlParameter("@koeficientParam", koeficient);
            SqlParameter idUserParam = new SqlParameter("@idUserParam", idUser);

            string sql = @"INSERT INTO Interesi (idOblastNaInteres, KoeficientNaInteres, idUser) VALUES (@idOblastInteresParam, @koeficientParam, @idUserParam)";
            SqlCommand command = new SqlCommand(sql, connection);

            command.Parameters.Add(idOblastInteresParam);
            command.Parameters.Add(koeficientParam);
            command.Parameters.Add(idUserParam);
    
            command.ExecuteNonQuery();
            connection.Close();
        }
        public static void EditInteresi(int idOblastInteres, int koeficient, int idUser)
        {
            SqlConnection connection = ConnectionMenager.GetConnection();

            SqlParameter idOblastInteresParam = new SqlParameter("@idOblastInteresParam", idOblastInteres);
            SqlParameter koeficientParam = new SqlParameter("@koeficientParam", koeficient);
            SqlParameter idUserParam = new SqlParameter("@idUserParam", idUser);

            string sql = @"UPDATE Interesi SET KoeficientNaInteres = @koeficientParam WHERE idUser=@idUserParam AND idOblastNaInteres=@idOblastInteresParam";
            SqlCommand command = new SqlCommand(sql, connection);

            command.Parameters.Add(idOblastInteresParam);
            command.Parameters.Add(koeficientParam);
            command.Parameters.Add(idUserParam);

            command.ExecuteNonQuery();
            connection.Close();
        }
    }
}
